//package io.renren.modules.app.oauth3;
//
//import io.renren.modules.app.entity.UserEntity;
//import io.renren.modules.app.entity.UserTokenEntity;
//import io.renren.modules.app.service.AppShiroService;
//import io.renren.modules.sys.entity.SysUserEntity;
//import io.renren.modules.sys.entity.SysUserTokenEntity;
//import io.renren.modules.sys.oauth2.OAuth2Token;
//import io.renren.modules.sys.service.ShiroService;
//import org.apache.shiro.authc.*;
//import org.apache.shiro.authz.AuthorizationInfo;
//import org.apache.shiro.authz.SimpleAuthorizationInfo;
//import org.apache.shiro.realm.AuthorizingRealm;
//import org.apache.shiro.subject.PrincipalCollection;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.stereotype.Component;
//
//import java.util.Set;
//
///**
// * @author LuoShun
// * @emall Lori6166@163.com
// * @date 2022/1/7 14:36
// */
//@Component
//public class UserRealm extends AuthorizingRealm {
//    @Autowired
//    private AppShiroService appShiroService;
//
//
//    @Override
//    protected AuthorizationInfo doGetAuthorizationInfo( PrincipalCollection principals )
//    {
//        return null;
//    }
//
//    @Override
//    public boolean supports(AuthenticationToken token) {
//        return token instanceof OAuth3Token;
//    }
//
//
//    /**
//     * 认证(登录时调用)
//     */
//    @Override
//    protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken token) throws AuthenticationException {
//        String accessToken = (String) token.getPrincipal();
//
//        //根据accessToken，查询用户信息
//        UserTokenEntity tokenEntity = appShiroService.queryByToken(accessToken);
//        //token失效
//        if(tokenEntity == null || tokenEntity.getExpireTime().getTime() < System.currentTimeMillis()){
//            throw new IncorrectCredentialsException("token失效，请重新登录");
//        }
//
//        //查询用户信息
//        UserEntity user = appShiroService.queryUser(tokenEntity.getUserId());
//        //账号锁定
//        if(user.getStatus() == 0){
//            throw new LockedAccountException("账号已被锁定,请联系管理员");
//        }
//
//        String realmName = getName();
//
//        SimpleAuthenticationInfo info = new SimpleAuthenticationInfo(user, accessToken, realmName);
//        return info;
//    }
//}
//
